/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pos.Driving.Path;

import javax.media.j3d.*;
import javax.vecmath.*;
import pos.Driving.Train.Train;
import pos.IModeController;
import pos.utils.ObjectFactory;

/**
 *
 * @author Administrator
 */
public class ATPSpeedSignture extends TransformGroup implements Attachable {

    private double D;
    private double speedLimit;
    private PosPoint P;
    private static Group model;
    
    public ATPSpeedSignture(double speedLimit) {
        if (model==null) model=ObjectFactory.createObject("Model.Rail.ATP.Speed");
        this.speedLimit=speedLimit;
    }

    @Override
    public boolean test(double d) {
        if (Math.abs(d-this.D)<3)
            return true;
        else 
            return false;
    }

    @Override
    public Object action(Train train) {
        train.setATPSpeedLimit(speedLimit);
        return speedLimit;
    }

    @Override
    public Object getInfo() {
        return new Double[]{D,speedLimit};
    }

    public void setSpeedLimit(double speedLimit) {
        this.speedLimit = speedLimit;
    }

    @Override
    public void setLocation(double d, PosPoint p) {
        this.D=d;
        this.P=p;
        Transform3D transH = new Transform3D(),
                transV = new Transform3D(),
                transT = new Transform3D();
        transH.rotX(P.AngH);
        transV.rotY(P.AngV);
        transT.set(new Vector3d(P.pos.x, P.pos.y, P.pos.z));
        transT.mul(transV);
        transT.mul(transH);
        this.setTransform(transT);
        this.addChild(model.cloneTree());
    }

    @Override
    public Object setParam(Object param) {
        return null;
    }
    
}
